package org.ucn.dmaa0914.gruppe6;

import java.util.ArrayList;

public class Container<T> {
	private ArrayList<T> items;
	
	public Container()
	{
		items = new ArrayList<T>();
	}
	
	public void add(T item)
	{
		items.add(item);
	}
	
	public void remove(T p)
	{
		items.remove(p);
	}
	
	public T find(int id)
	{
		for(T p : items)
		{
			if( ((IdObject)p).getId() == id )
			{
				// Item found, return it
				return p;
			}
		}
		
		// None found
		return null;
	}	
	public ArrayList<T> search(String data, SearchFilter<T> filter)
	{
		ArrayList<T> result = new ArrayList<T>();
		
		for(T p : items)
		{
			if( filter.isCandidate(p, data) )
			{
				result.add(p);
			}
		}
		
		return result;
	}	
}
